//递归
public class recursion {
    public static int fib2(int n)
    {
        if(n == 1 || n == 2) {
            return 1;
        }

        int f3 = 1;
        int f2 = 1;
        int f1 = 1;
        for(int i = 3; i <= n; i++)
        {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }
    public static int fib(int n)
    {
        if(n == 1)
        {
            return 1;
        }
        if(n == 2)
        {
            return 1;
        }

        return fib(n - 1) + fib(n - 2);
    }
    public static int add(int n)
    {
        if(n<10)
        {
            return n;
        }
        return n % 10 + add(n / 10);
    }
    public static int sum(int n)
    {
        if(n==1)
        {
            return n;
        }

        return n + sum(n-1);
    }
    public static void print(int n)
    {

        if(n<10)
        {
            System.out.print(n + " ");
            return;
        }
        print(n/10);
        System.out.print(n%10+" ");
    }
    public static void main(String[] args) {
//        print(1234);
//        System.out.println(sum(10));
//        System.out.println(add(1729));
//        System.out.println(fib(40));
        System.out.println(fib2(40));
    }
}
